<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
  <title>get_color_num (Table)</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
  <pre><span class="ruby-comment cmt"># File ansi.rb, line 34</span>
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">get_color_num</span> <span class="ruby-identifier">num</span>,<span class="ruby-identifier">bf</span>=<span class="ruby-keyword kw">nil</span>
  <span class="ruby-identifier">cols</span> = {
           <span class="ruby-identifier">:fore=</span><span class="ruby-operator">&gt;</span>{
                   <span class="ruby-identifier">:red=</span><span class="ruby-operator">&gt;</span><span class="ruby-value">31</span>,
                   <span class="ruby-identifier">:black=</span><span class="ruby-operator">&gt;</span><span class="ruby-value">30</span>,
                   <span class="ruby-identifier">:green=</span><span class="ruby-operator">&gt;</span><span class="ruby-value">32</span>,
                   <span class="ruby-identifier">:yellow=</span><span class="ruby-operator">&gt;</span><span class="ruby-value">33</span>,
                   <span class="ruby-identifier">:blue=</span><span class="ruby-operator">&gt;</span><span class="ruby-value">34</span>,
                   <span class="ruby-identifier">:magenta=</span><span class="ruby-operator">&gt;</span><span class="ruby-value">35</span>,
                   <span class="ruby-identifier">:cyan=</span><span class="ruby-operator">&gt;</span><span class="ruby-value">36</span>,
                   <span class="ruby-identifier">:white=</span><span class="ruby-operator">&gt;</span><span class="ruby-value">37</span>,
                   <span class="ruby-identifier">:default=</span><span class="ruby-operator">&gt;</span><span class="ruby-value">39</span>
                  },
           <span class="ruby-identifier">:font=</span><span class="ruby-operator">&gt;</span>{
                    <span class="ruby-identifier">:bold=</span><span class="ruby-operator">&gt;</span><span class="ruby-value">1</span>,
                    <span class="ruby-identifier">:underline=</span><span class="ruby-operator">&gt;</span><span class="ruby-value">4</span>,
                    <span class="ruby-identifier">:strike=</span><span class="ruby-operator">&gt;</span><span class="ruby-value">9</span>,
                    <span class="ruby-identifier">:italic=</span><span class="ruby-operator">&gt;</span><span class="ruby-value">3</span>
                  },
           <span class="ruby-identifier">:back=</span><span class="ruby-operator">&gt;</span>{
                   <span class="ruby-identifier">:red=</span><span class="ruby-operator">&gt;</span><span class="ruby-value">41</span>,
                   <span class="ruby-identifier">:black=</span><span class="ruby-operator">&gt;</span><span class="ruby-value">40</span>,
                   <span class="ruby-identifier">:green=</span><span class="ruby-operator">&gt;</span><span class="ruby-value">42</span>,
                   <span class="ruby-identifier">:yellow=</span><span class="ruby-operator">&gt;</span><span class="ruby-value">43</span>,
                   <span class="ruby-identifier">:blue=</span><span class="ruby-operator">&gt;</span><span class="ruby-value">44</span>,
                   <span class="ruby-identifier">:magenta=</span><span class="ruby-operator">&gt;</span><span class="ruby-value">45</span>,
                   <span class="ruby-identifier">:cyan=</span><span class="ruby-operator">&gt;</span><span class="ruby-value">46</span>,
                   <span class="ruby-identifier">:white=</span><span class="ruby-operator">&gt;</span><span class="ruby-value">47</span>,
                   <span class="ruby-identifier">:default=</span><span class="ruby-operator">&gt;</span><span class="ruby-value">49</span>
                  }
         }
  <span class="ruby-identifier">col</span> = <span class="ruby-identifier">cols</span>[<span class="ruby-identifier">:fore</span>].<span class="ruby-identifier">find</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span> <span class="ruby-identifier">x</span>[<span class="ruby-value">1</span>]<span class="ruby-operator">==</span><span class="ruby-identifier">num</span>}
  <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">col</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">bf</span>
    <span class="ruby-identifier">col</span> = [<span class="ruby-node">&quot;fore:#{col[0]}&quot;</span>]
  <span class="ruby-keyword kw">end</span>
  <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">col</span>
      <span class="ruby-identifier">col</span> = <span class="ruby-identifier">cols</span>[<span class="ruby-identifier">:back</span>].<span class="ruby-identifier">find</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span> <span class="ruby-identifier">x</span>[<span class="ruby-value">1</span>]<span class="ruby-operator">==</span><span class="ruby-identifier">num</span>}
      <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">col</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">bf</span>
        <span class="ruby-identifier">col</span> = [<span class="ruby-node">&quot;back:#{col[0]}&quot;</span>]
      <span class="ruby-keyword kw">end</span>
  <span class="ruby-keyword kw">end</span>
  <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">col</span>
      <span class="ruby-identifier">col</span> = <span class="ruby-identifier">cols</span>[<span class="ruby-identifier">:font</span>].<span class="ruby-identifier">find</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span> <span class="ruby-identifier">x</span>[<span class="ruby-value">1</span>]<span class="ruby-operator">==</span><span class="ruby-identifier">num</span>}
  <span class="ruby-keyword kw">end</span>
  <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">col</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">to_s</span>
<span class="ruby-keyword kw">end</span></pre>
</body>
</html>